from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel

from account.user_management import check_user
from account.schemas import ApiResponse, AccountDetail, Equation
from solver.eqsolver import solveEq

router = APIRouter()


@router.post("")
async def eqsolver(eq: Equation, user: AccountDetail = Depends(check_user)):
    if user.error:
        raise HTTPException(status_code=401, detail=user.error)
    if user.role not in ["admin", "vip"]:
        raise HTTPException(status_code=401, detail='user not authorized')
    data = solveEq(eq.ctt)
    return ApiResponse(status_code=200, message="success", data=data)
